package org.msfj.admin.api;

import org.msfj.admin.feign.DeptApi;
import org.msfj.admin.model.Dept;
import org.msfj.admin.org.service.DeptService;
import org.msfj.admin.vo.DeptVo;
import org.msfj.admin.feign.DeptApi;
import org.msfj.admin.model.Dept;
import org.msfj.admin.org.service.DeptService;
import org.msfj.admin.vo.DeptVo;
import org.msfj.admin.feign.DeptApi;
import org.msfj.admin.model.Dept;
import org.msfj.admin.org.service.DeptService;
import org.msfj.admin.vo.DeptVo;
import org.msfj.common.model.CommonResult;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api")
public class DeptApiImpl implements DeptApi {


    org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DeptService deptService;

    @GetMapping("/dept/getById")
    @Override
    public CommonResult<DeptVo> getById(@RequestParam("id") String id) {
        Dept byId = deptService.getById(id);
        if (byId != null) {
            DeptVo data = deptService.setOtherProperties(byId);
            return CommonResult.ok(data);
        }
        logger.error("没有查到id 是" + id + "的部门");
        return CommonResult.error("没有查到id 是" + id + "的部门");
    }

    @Override
    @RequestMapping("/dept/all")
    public CommonResult<List<DeptVo>> getAllVo() {
        List<DeptVo> deptTree = deptService.getDeptTree();
        return CommonResult.ok(deptTree);
    }
}
